const handleBlogRoute = require("./src/routes/blog.js")
const querystring=require("querystring")

const serverHandler = (req, res) => {
	
	res.setHeader('Content-Type', 'application/json');
	
	const url=req.url;
	//获取路由
	req.path=url.split('?')[0];
	//获取get参数
	req.query=querystring.parse(url.split('?')[1])
	// 返回参数
	const blogData = handleBlogRoute(req, res)
	if (blogData) {
		res.end(JSON.stringify(blogData))
		return
	}
	//未找到路由
	res.writeHead(404,{"Content-type":"text/plain"});
	res.write("404 NOT FOUND")
	res.end()
}
module.exports = serverHandler
